package org.example.c_0_006;

import org.junit.Test;

public class T_ThreadLocal {
    ThreadLocal<String> threadLocal = new ThreadLocal<>();

    @Test
    public void test() throws InterruptedException {
        threadLocal.set("主线程");
        Thread thread = new Thread(() -> {
            threadLocal.set("线程1");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(threadLocal);
            System.out.println("线程1获取到的：" + threadLocal.get());
        });
        thread.start();
        Thread.sleep(1000);
        System.out.println(threadLocal);
        System.out.println("主线程获取到的："+threadLocal.get());

        thread.wait();
        thread.join();
    }
}
